var util = require('../../libs/util.js');
//获取应用实例
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    StatusBar: app.globalData.StatusBar,
    CustomBar: app.globalData.CustomBar
  },
  onPullDownRefresh () {
    //wx.stopPullDownRefresh()
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      CO_NAME: app.globalData.CO_NAME || app.globalData.truename,
      roleName: util.roleToName(app.globalData.role_default),
      role: app.globalData.role_default,
      CO_ID: app.globalData.CO_ID
    })
    this.loadData();
  },
  loadData: function () {
    var that = this;
    util.getData("/atapi/enterprise/enterprise/basestat", {
    }, function (res, error) {
      console.log(res); console.log(error)
      if (res.data.success) {
        that.setData({
          enterpriseNumber: res.data.enterprise || 0,
          operationNumber: res.data.operation || 0,
          scheduleNumber: res.data.schedule||0,
          fleetNumber: res.data.fleet || 0,
          financeNumber: res.data.finance || 0,
          warehouseNumber: res.data.warehouse || 0,
          shopNumber: res.data.shop || 0,
          vehicleNumber: res.data.vehicle || 0,
          driverNumber: res.data.driver || 0,
          carrierNumber: res.data.carrier || 0,
          sub_carrier: res.data.sub_carrier,
          customerNumber: res.data.customer || 0,
          semitrailerNumber:res.data.semitrailer||0,
          containerYardNumber:res.data.containeryard||0,
          messageNumber:res.data.message||0
        });
      }
    });
  },
  toSetting: function (e) {
    wx.navigateTo({
      url: '/pages/enterprise/config'
    })
  },
  gotoApp:function(e){
    if (!app.globalData.CO_CODE){
        this.setData({
          modalName : 'NoROLE'
        })
        return false;
     }
     var url = e.currentTarget.dataset.url;
     if(url == ''){
      wx.showToast({
        title: e.currentTarget.dataset.text,
        image: '/images/wrong.png',
        duration: 3000
      });
      return false;
     }
     wx.navigateTo({
       url: url
     })
  },
  showModal(e) {
    this.setData({
      modalName: e.currentTarget.dataset.target
    })
  },
  hideModal(e) {
    this.setData({
      modalName: null
    })
  },
  perfectInformation:function(){
     wx.redirectTo({
       url: '/pages/auth/enterpriseReg',
     })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})